﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lib.Query;
using System.Linq.Expressions;
using System.Runtime.Serialization;

namespace Model.Queries
{
    [Serializable()]
    [KnownType(typeof(MotorPolicyQuery))]
    public class PolicyQuery : LiteQuery<Policy>
    {

        public PolicyQuery()
        {
            this.OrderBy(x => x.Id, false);
        }

        private int _id;
        
        public int Id 
        {
            get { return _id; }
            set 
            {
                _id = value;
                this.Add<Policy>(x => x.Id, CriteriaOperator.Equal, value); 
            }
        }

        private long _number;

        public long Number
        {
            get { return _number; }
            set 
            {
                _number = value;
                this.Add<Policy>(x => x.Number, CriteriaOperator.Equal, value); 
            }
        }

        private string _personName;

        public string PersonName
        {
            get { return _personName; }
            set 
            {
                _personName = value;
                if(!string.IsNullOrWhiteSpace(value))
                    this.Add<Policy>(x => x.Person.Name, CriteriaOperator.Like, value); 
            }
        }

        private int _personId;

        public int PersonId
        {
            get { return _personId; }
            set 
            {
                _personId = value;
                this.Add<Policy>(x => x.Person.Id, CriteriaOperator.Equal, value); 
            }
        }
    }
}
